<%--
  Created by IntelliJ IDEA.
  User: 494418174
  Date: 2020/3/20 0020
  Time: 10:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">订单号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="orderId" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入订单号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">派送员姓名:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="delivererName" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入派送员姓名" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">用户姓名:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="userName" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入用户姓名" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">起始时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="createTime1" id="createTime1" autocomplete="off"
                       class="layui-input layui-input-inline"
                       placeholder="请输入起始时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="createTime2" id="createTime2" autocomplete="off"
                       class="layui-input layui-input-inline"
                       placeholder="请输入结束时间" style="height: 30px;border-radius: 10px">
            </div>
            <button type="button" class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm " lay-submit lay-filter="formDemo">查询
            </button>
            <button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm">重置
            </button>
        </div>

    </div>

</form>

<!-- 搜索条件结束 -->

<table id="orderTable" lay-filter="orderTable"></table>


<script id="barOrder" type="text/html">
     {{#  if(d.identity ==""){ }}

        {{#  }else{ }}
    <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">确认订单完成</a>
    {{# }}}
    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">废除</a>
</script>


<!-- 确认订单弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form layui-row layui-col-space10" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md9 layui-col-xs7">

                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">订单号:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="hidden" name="identity" >
                            <input type="hidden" name="userId" >
                            <input type="text" name="orderId" id="orderId" autocomplete="off" class="layui-input layui-btn-disabled"
                                   lay-verify="required"
                                   placeholder="" style="height: 30px;border-radius: 10px">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">派送员姓名:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="text" name="delivererName" autocomplete="off" class="layui-input layui-btn-disabled"
                                   lay-verify="required"
                                   placeholder="" style="height: 30px;border-radius: 10px">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户姓名:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="text" name="userName"  autocomplete="off" class="layui-input layui-btn-disabled"
                                   placeholder="" style="height: 30px;border-radius: 10px;width: 250px">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">支付金额:</label>
                <div class="layui-input-block" style="padding: 5px">
                    <input type="text" name="money"  autocomplete="off" class="layui-input layui-btn-disabled"
                           placeholder="" style="height: 30px;border-radius: 10px;width: 250px">
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">生成时间:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="createTime" class="layui-input layui-btn-disabled"
                               placeholder="" style="height: 30px;border-radius: 10px">
                    </div>
                </div>

            </div>
            <div class="layui-form-item magb0">
                <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                    <button type="button"
                            class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                            lay-filter="doSubmit" lay-submit="">确认完成
                    </button>

                </div>
            </div>
        </div>
    </form>
</div>
<%-- 确认订单弹出框结束 --%>

<script src="/layui/layui.js"></script>
<script>
    var orderTable
    var index
    var url
    layui.use(['table', 'form', 'layer', 'jquery', 'laydate'], function () {
        var table = layui.table
        var form = layui.form
        var layer = layui.layer
        var $ = layui.jquery
        var laydate = layui.laydate
        laydate.render({
            elem: '#createTime1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#createTime2'
            , type: 'datetime'
        });
        // 初始table
        orderTable = table.render({
            elem: "#orderTable"
            , url: "/adminOrder/findOrder"
            , page: {limit: 5, limits: [5, 10, 15]}
            , cellMinWidth: 80
            , cols: [[ //表头
                {field: 'orderId', title: '订单号', fixed: 'center'}
                , {field: 'userId', title: '用户id', fixed: 'center',hide:true}
                , {field: 'identity', title: '派送员身份证', fixed: 'center',hide:true,templet:function (d) {

                    }}
                , {field: 'userName', title: '用户姓名', fixed: 'center'}
                , {field: 'delivererName', title: '派送员姓名', fixed: 'center'}
                , {field: 'money', title: '支付金额', fixed: 'center'}
                , {field: 'createTime', title: '创建时间', fixed: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barOrder', width: 200}
            ]]
        })

        // 查询
        form.on("submit(formDemo)", function (data) {
            orderTable.reload({
                url: "/adminOrder/findOrder"
                , where: {
                    'orderId': data.field.orderId
                    , 'delivererName': data.field.delivererName
                    , 'userName': data.field.userName
                    , 'createTime1': data.field.createTime1
                    , 'createTime2': data.field.createTime2

                }
                , page: {
                    curr: 1
                }
            })
            return false;
        })

        //监听行工具事件
        table.on('tool(orderTable)', function (obj) {
            var data = obj.data
            if (obj.event == "edit") {
                menuShow(data)
            } else if (obj.event == "del") {
                del(data)
            }
        })

        function del(data) {


            layer.confirm("您确定要废除该订单么?", function (ind) {

                $.post("/adminOrder/delOrder", {"orderId": data.orderId}, function (d) {
                    layer.msg(d.msg)
                    // 刷新table数据
                    orderTable.reload()

                })
                layer.close(ind)
            })


        }

        function menuShow(data) {
            index = layer.open({
                type: 1
                , title: "确认订单完成"
                , content: $("#saveOrUpdateDiv")
                , area: ['800px', '440px']
                , success: function (layero, index) {
                    form.val("dataFrm", data)
                    url = "/endOrder/overOrder"
                }
            })
        }

        // form表达提交
        form.on("submit(doSubmit)", function () {
            layer.confirm("您确定要提交该数据么", function (ind) {
                $.post(url, $("#dataFrm").serialize(), function (data) {
                    layer.msg(data.msg)
                    layer.close(index)
                    orderTable.reload()
                })
                layer.close(ind)
            })


        })
    })

</script>
</body>
</html>

